	PROGRAM POSTSCRIPT
C *** LAST REVISED ON 15-MAR-1988 08:33:33.75
C *** SOURCE FILE: [DL.GRAPHICS.LONGLIB]POSTSCRIPT.FOR
C
C	CREATED: DGL 4-APR-1985
C
C	THIS PROGRAM CONVERTS THE PRINTER GRAPHICS FILE
C	PRODUCED BY THE LONGLIB GRAPHICS LIBRARY 
C	TO THE POSTSCRIPT LANGUAGE.
C
	CHARACTER*80 NAME
C
C	VAX DEPENDENT ROUTINE TO GET COMMAND LINE FILE NAME
C
	IERR=LIB$GET_FOREIGN(NAME,,IFLAG)
C
C	DEFAULT NAME
C
	IF (NAME.EQ.' ') NAME='FOR003.DAT'	! DEFAULT FILE NAME
	CALL LPLOT(NAME)
	STOP
	END
C
	SUBROUTINE LPLOT(NAME)
C
C	MAIN ROUTINE TO CONVERT PRINTER GRAPHICS FILE TO POSTSCRIPT
C
C	NAME	(CHARACTER)	FILE NAME
C
C
	CHARACTER*(*) NAME
C
C	DEFINITIONS FOR LINE TYPES
C
	CHARACTER*13 LINETYPE(10)
	DATA LINETYPE(1)/'[]'/,LINETYPE(2)/'[8 8]'/,LINETYPE(3)/'[4 4]'/
	DATA LINETYPE(4)/'[4 7]'/,LINETYPE(5)/'[2 2]'/
	DATA LINETYPE(6)/'[2 2 2 2 4]'/,LINETYPE(7)/'6 2 3 2 4'/
	DATA LINETYPE(8)/'[1 1]'/,LINETYPE(9)/'[1 1 4 4]'/
	DATA LINETYPE(10)/'[1 1 2 2 3 3]'/
C
	INTEGER PENUP
C
C	INITIALIZE VARIABLES
C
C	LW=-1		! LINE WIDTH (INVALID TO FORCE NEW WIDTH)
C	LT=-1		! LINE TYPE (INVALID TO FORCE NEW TYPE)
C	LC=-1		! LINE COLOR (INVALID TO FORCE NEW TYPE)
C
	LW=-1
	LT=-1
	LC=-1
	MP=999
	IXOLD=0
	IYOLD=0
C
C	PENUP IS PEN CONTROL FLAG (0=NO SEGMENT, 2=PEN UP, 3=PEN DOWN)
C
	PENUP=0
C
C	OPEN INPUT FILE PRODUCED BY LONGLIB GRAPHICS LIBRARY
C
	OPEN(UNIT=2,FILE=NAME,FORM='UNFORMATTED',STATUS='OLD',
     $		READONLY,ERR=99)
C
C	OPEN OUTPUT FILE
C
	OPEN(UNIT=1,FILE='OUT.LIS',FORM='FORMATTED',STATUS='NEW')
C
C	SEND INITIALIZATION CODES TO OUTPUT FILE
C
 	WRITE (1,300)
300	FORMAT(X,'/inch {1000} def'/	! 1000'S OF INCH RESOLUTION
     $		X,'gsave'/,		! SAVE CURRENT GRAPHICS STATE
     $ 		X,'0 setlinejoin'/,	! LINE JOIN TYPE
     $		X,'1 setlinecap')	! LINE END CAP
C
C	TOP OF LONGLIB META-FILE READ LOOP
C
1000	CONTINUE
C
C	READ INITIAL COMMAND CODE AND PARAMETERS FROM LONGLIB META-FILE
C
	CALL REGET(M1,M2,M3,MP,2)
C
C	CHECK END OF FILE
C
	IF (M3.EQ.11) GOTO 110
	SX=M1
	SY=M2
	IF (M1.EQ.0.OR.M2.EQ.0) GOTO 110
  1	CONTINUE
C
C	READ COMMAND CODE AND PARAMETERS FROM LONGLIB META-FILE
C
	CALL REGET(M1,M2,M3,MP,2)
C
C	COORDINATE TRANSFORM
C
	Y1=M1/SX
	X1=M2/SY
	I3=M3
	IOLD=-1
C
C	CHECK END OF FILE
C
	IF (M3.GT.999) GOTO 999
C
C	EXECUTE META-FILE COMMAND
C
	GOTO (10,20,20,10,10,10,10,10,20,100,110) I3
10	GOTO 1
C
C	INTERPRET COMMAND
C
20	CONTINUE
C
C	"CALL PLOT(X1,Y1,I3)"
C
C	CONVERT TO INTEGER 1000'S INCH
C
	IY=INT(Y1*1000+0.5)
	IX=INT(X1*1000+0.5)
	IF (I3.EQ.3) THEN
C
C	PEN UP MOVE
C
		IF (PENUP.EQ.2) WRITE (1,601) IXOLD,IYOLD
601		FORMAT(X,I6,X,I6,X,'moveto closepath stroke')
		PENUP=3
	ELSE
C
C	PEN DOWN MOVE
C 				! PEN DOWN MOVE
		IF (PENUP.EQ.3) THEN
			WRITE (1,600)
600			FORMAT(X,'newpath')
			WRITE (1,602) IXOLD,IYOLD
602			FORMAT(X,I6,X,I6,X,'moveto')
		ENDIF
		PENUP=2
		WRITE (1,603) IX,IY
603		FORMAT(X,I6,X,I6,X,'lineto')
	ENDIF
	IXOLD=IX
	IYOLD=IY
	GOTO 1
C
100	CONTINUE
C
C	"CALL NEWPAGE"
C
	IF (PENUP.EQ.2) THEN
		WRITE (1,601) IXOLD,IYOLD
		PENUP=0
	ENDIF
	WRITE (1,402)
402	FORMAT(X,'showpage')
	GOTO 1
C
C	SPECIAL COMMANDS
C
999	GOTO (1000,1001,1002,1003) I3-999
2000	GOTO 1
C
C	NEW PEN/LINE TYPE
C
1001	CONTINUE
	IF (M1.LT.0) M1=0
	IF (M1.GT.9) M1=MOD(M1,10)
	IF (M1.NE.LT) THEN
		IF (PENUP.EQ.2) THEN
			WRITE (1,601) IXOLD,IYOLD
			PENUP=0
		ENDIF
		WRITE (1,403) LINETYPE(M1+1)
		LT=M1
	ENDIF
403	FORMAT(X,A13,' 0 setdash')
	GOTO 1
C
C	LINE COLOR
C
1002	CONTINUE
	LW=M1
C
C	INCLUDE PEN COLOR AS GREY SCALE (0-16) BLACK=16, WHITE=0
C
	IF (M2.NE.LC) THEN
C
C	"CALL PLOT(FLOAT(M2),0.,0)"
C
		WRITE (1,407) FLOAT(M2)/16.
407		FORMAT(X,F4.2,' setgrey')
	ENDIF
	LC=M2
	GOTO 1
C
C	LINEWIDTH
C
1003	CONTINUE
C
C	"CALL NEWPEN(I3)"
C
	IF (M1.LE.0) M1=1
C
C	NOTE: THE LINEWIDTH IS GRAPHICS DEVICE DEPENDENT AND MAY VARY
C	DEPENDING ON LINE ORIENTATION
C
	IF (M1.NE.LW) THEN
		IF (PENUP.EQ.2) THEN
			WRITE (1,601) IXOLD,IYOLD
			PENUP=0
		ENDIF
C
C	NEW LINE WIDTH
C
		WRITE (1,404) M1
404		FORMAT(X,I2,' setlinewidth')
	ENDIF
	GOTO 1
C
C	CLOSE INPUT FILE
C
110	CLOSE(2)
C
	IF (PENUP.EQ.2) THEN
		WRITE (1,601) IXOLD,IYOLD
		PENUP=0
	ENDIF
C
	WRITE (1,410)
410	FORMAT(X,'showpage')
C
C	CLOSE OUTPUT FILE
C
	CLOSE(1)
 99	RETURN
	END
C
	SUBROUTINE REGET(M1,M2,M3,MP,ILU)
C
C	READ DATA FROM LONGLIB META-FILE PRINTER DATA FILE
C	
	INTEGER*2 M(128)
	MP=MP+3
	IF (MP.GT.128) THEN
		READ (ILU,ERR=99) M
		MP=3
	ENDIF
	M3=M(MP)
	M2=M(MP-1)
	M1=M(MP-2)
	IF (M3.EQ.999) GOTO 99
	RETURN
99	M3=11
	RETURN
	END
